/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/18
*/
#ifndef __EDUI_ANIMATION_H__
#define __EDUI_ANIMATION_H__

#include "../controls/Control.h"
#include "Mgr.h"

EDUI_NAMESPACE_BEGIN

class ISurface;
class ITexture;

typedef struct AnimationFrame
{
    ITexture* texture;
    int id;             //texture'id.
    int x,y;
    int w,h;
    int delay;
} AnimationFrame;

class EDUI_API Animation
{
protected:
    Animation();
    virtual ~Animation();
public:
	static Animation* GetInterface();
	void Release();
#ifdef EDUI_TEST_NEW_DELETE
    static int m_newdeleteNum;
    static int _GetNewDeleteNum();
#endif
public:
    void Destroy();
    bool IsOK();
public:
    bool Create(IWindow* wnd, const char* name, int id = -1);
    //add one or more frame
    bool AddFrame(const char* img, int id = -1);
    bool AddFrame(int imgid, int id = -1);
    //add one frame
    bool AddFrame(AnimationFrame* frame, int id = -1);
    void RemoveFrame(int id);
    void RemoveFrame(AnimationFrame* frame);
    size_t FrameCount();
    
    //control will Invaldate
    void AddNotify(Control* ctrl);
    void RemoveNotify(Control* ctrl);
    size_t NotifyCount();

    void Start(int interval = 500);
    void Stop();
    bool IsRun();
    void Reset();
    AnimationFrame* GetFrame(int id);
    AnimationFrame* GetCurFrame();

    void Notify(bool bAddFrame = false);
protected:
    IWindow* m_wnd;
    MgrSimple<AnimationFrame> *m_frames;
    MgrSimple<Control> *m_ctrls;
    size_t m_curFrame;
    TimerID m_timer;
};

EDUI_NAMESPACE_END

#endif